let dbhelp = require('../../util/Dbhelp');
// 获取推荐页轮播图
const dbRebanner = async ()=>{
    let data = await dbhelp.sql("select * from RecommendBanner")
    return  data.recordset
}
// 获取手机
const dbPhone = async (obj)=>{
    let data = await dbhelp.sql(`select * from Phone where hot=${obj.hot==1?1:0}`)
    return  data.recordset
}
// 获取电脑
const dbComputer = async (obj)=>{
    let data = await dbhelp.sql(`select * from Computer where hot=${obj.hot==1?1:0}`)
    return  data.recordset
}
// 获取推荐菜单栏图片
const dbReTabImg = async () =>{
    let data = await dbhelp.sql(`select * from RecommendTabimg`)
    return  data.recordset
}
// 智能页内容
const dbSmartBanner = async () =>{
    let data = await dbhelp.sql(`select * from SmartBanner`)
    return  data.recordset
}
const dbSmartTabimg = async () =>{
    let data = await dbhelp.sql(`select * from SmartTabimg`)
    return  data.recordset
}
const dbSmartNew = async () =>{
    let data = await dbhelp.sql(`select * from SmartNew`)
    return  data.recordset
}
const dbAppliances = async (obj) =>{
    let data = await dbhelp.sql(`select * from Appliances where hot=${obj.hot==1?1:0}`)
    return  data.recordset
}
const dbEarphone = async (obj) =>{
    let data = await dbhelp.sql(`select * from Earphone where hot=${obj.hot==1?1:0}`)
    return  data.recordset
}
const dbLight = async (obj) =>{
    let data = await dbhelp.sql(`select * from Light where hot=${obj.hot==1?1:0}`)
    return  data.recordset
}
const dbBalanceCar = async (obj) =>{
    let data = await dbhelp.sql(`select * from BalanceCar where hot=${obj.hot==1?1:0}`)
    return  data.recordset
}
const dbClean = async (obj) =>{
    let data = await dbhelp.sql(`select * from Clean where hot=${obj.hot==1?1:0}`)
    return  data.recordset
}
const dbFittingConsumable = async (obj) =>{
    let data = await dbhelp.sql(`select * from FittingConsumable where hot=${obj.hot==1?1:0}`)
    return  data.recordset
}
// 电视页
const dbTvdata = async (obj) =>{
    let data = await dbhelp.sql(`select * from Tv where type=${obj.type?obj.type:0} and state=1`)
    console.log(`select * from Tv where type=${obj.type?obj.type:0} and state=1`);
    return  data.recordset
}
const dbTvMore = async () =>{
    let damiboxta = await dbhelp.sql(`select * from mibox where state=1`);
    let Projector = await dbhelp.sql(`select * from Projector where state=1`)
    let Fridge = await dbhelp.sql(`select * from Fridge where state=1`)
    return  {
        damiboxta:damiboxta.recordset,
        Projector:Projector.recordset,
        Fridge:Fridge.recordset
    }
}
// 家电页
// 更多好物
const dbHomeAppliancesMore = async () => {
    let data = await dbhelp.sql(`select * from HomeAppliancesMore`)
    return data.recordset
}
// 分类一级菜单
const dbOneRank = async () => {
    let data = await dbhelp.sql(`select * from Classify where rank=1`);
    return  data.recordset
}
// 分类的内容
const dbGoods = async (obj)=>{
    let one = await dbhelp.sql(`select * from Classify where parent_ID=${obj.id}`);
    for (let i = 0; i < one.recordset.length; i++) {
        let tow = await dbhelp.sql(`select * from Goods where towID=${one.recordset[i].id}`)
        one.recordset[i]["goodslist"] = tow.recordset;
    }
    return one.recordset
}
module.exports = {
    dbRebanner,dbPhone,dbComputer,dbReTabImg,
    dbSmartBanner, dbSmartTabimg, dbSmartNew, dbAppliances, dbEarphone, dbLight, dbBalanceCar, dbClean, dbFittingConsumable,
    dbTvdata,dbTvMore,
    dbHomeAppliancesMore,
    dbOneRank,dbGoods,
}